<extend name="Layout/application"/>

<block name="content">
    <div class="row">
        <div class="col-md-12">

            <div class="row">
                <div class="col-md-8">
                    <div class="page-header">
                        <h1>系统信息</h1>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-10">
                    <div class="panel panel-default">
                        <div class="panel-heading">友情链接</div>
                        <div class="panel-body">
                            <table class="table">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" class="select_all"></th>
                                    <th>ID</th>
                                    <th>名称</th>
                                    <th>网址</th>
                                    <th>排序</th>
                                    <th>&nbsp;&nbsp;编辑</th>
                                </tr>
                                </thead>
                                <form method="post" action="" id="form">
                                    <tbody>
                                    <volist name="links" id="l">
                                        <tr>
                                            <input type="hidden" name="sort_id[]" value="{{$l.id}}">
                                            <td><input type="checkbox" class="select" name="del_id[]" value="{{$l.id}}"></td>
                                            <td class="id">{{$l.id}}</td>
                                            <td class="name"><a href="{{$l.url}}" target="_blank">{{$l.name}}</a></td>
                                            <td class="url">{{$l.url}}</td>
                                            <td><input type="text" name="sort_order[]" value="{{$l.sort_order}}"></td>
                                            <td><a style="cursor:pointer" class="edit_link" data-toggle="modal"
                                                   data-target="#edit"><span class="glyphicon glyphicon-pencil"
                                                                             href=""></span></a>&nbsp;&nbsp;&nbsp;&nbsp;
                                                <a href="{{:U('destory',array('id'=>$l['id']))}}"
                                                   style="cursor: pointer" onclick="return confirm('确认删除吗？')"><span
                                                        class="glyphicon glyphicon-trash" href=""></span></a>>
                                            </td>
                                        </tr>
                                    </volist>
                                    </tbody>
                                </form>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="list-group">
                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sort_category"
                           data-toggle="modal" data-target="#store">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 新增 (add)
                        </a>

                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sort_category" id="sort_order">
                            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 排序 (sort)
                        </a>

                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sort_category" id="destroy_all">
                            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 删除 (destroy)
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- Modal -->
    <div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel1">编辑友情链接</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form" method="post" action="{{:U('update')}}">
                        <input type="text" name="id" class="id_edit">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">名称</label>
                            <div class="col-sm-10">
                                <input type="text" name="name" class="form-control name_edit" id="inputEmail">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword1" class="col-sm-2 control-label">网址</label>
                            <div class="col-sm-10">
                                <input type="text" name="url" class="form-control url_edit" id="inputPassword1">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>


    <!-- Modal -->
    <div class="modal fade" id="store" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">新增友情链接</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form" method="post" action="{{:U('store')}}">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">名称</label>
                            <div class="col-sm-10">
                                <input type="text" name="name" class="form-control" id="inputEmail3"
                                       placeholder="请输入链接名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label">网址</label>
                            <div class="col-sm-10">
                                <input type="text" name="url" class="form-control" id="inputPassword3"
                                       placeholder="请输入网址">
                            </div>
                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>


                    </form>
                </div>
            </div>
        </div>
    </div>
</block>

<block name="js">
    <script>
        $(function () {
            $(".edit_link").click(function () {
                var id = $(this).parent().siblings(".id").text();
                var name = $(this).parent().siblings(".name").text();
                var url = $(this).parent().siblings(".url").text();
                $(".id_edit").val(id);
                $(".name_edit").val(name);
                $(".url_edit").val(url);
            });

            $(".select_all").click(function () {
                //$a = $(this).prop("checked");
                //console.log($a);
                $(".select").prop("checked", this.checked);
            });

            $("#destroy_all").click(function () {
                var $len = $(".select:checked").length;
                if($len==0){
                    alert("您必须选择一个选项删除！");
                    return false;
                }
                $("#form").attr("action","{{:U('destroy_all')}}").submit();
            });

            $("#sort_order").click(function () {
                $("#form").attr("action","{{:U('sort_order')}}").submit();
            })
        })
    </script>
</block>


